#include "env.h"
#include "log.h"
#include <iostream>

johnsonli::Logger::ptr g_logger = LOG_ROOT();


struct A {
    A() {
        std::ifstream ifs("/proc/" + std::to_string(getpid()) + "/cmdline", std::ios::binary);
        std::string content;
        content.resize(4096);

        ifs.read(&content[0], content.size());
        content.resize(ifs.gcount());

        for(size_t i = 0; i < content.size(); ++i) {
            std::cout << i << " - " << content[i] << " - " << (int)content[i] << std::endl;
        }
    }
};

A a;


int main(int argc, char** argv)
{
    johnsonli::EnvMgr::GetInstance()->addHelp("d", "run in daemon");
    johnsonli::EnvMgr::GetInstance()->addHelp("p", "print help");
    johnsonli::EnvMgr::GetInstance()->addHelp("s", "start in terminal");
    if(!johnsonli::EnvMgr::GetInstance()->init(argc, argv))
    {
        johnsonli::EnvMgr::GetInstance()->printHelp();
        return 0;
    }

    LOG_INFO(g_logger) << "exe: " << johnsonli::EnvMgr::GetInstance()->getExe();
    LOG_INFO(g_logger) << "cwd: " << johnsonli::EnvMgr::GetInstance()->getCwd();
    LOG_INFO(g_logger) << "path: " << johnsonli::EnvMgr::GetInstance()->getEnv("PATH", "XXX");


    if(johnsonli::EnvMgr::GetInstance()->has("p"))
    {
        johnsonli::EnvMgr::GetInstance()->printHelp();
    }

    return 0;

}

